import { defineStore } from "pinia";
import { computed, ref } from "vue";

export const useGoods = defineStore("goods",()=>{
    // 定义state
    const goodsList = ref([
        {name:'苹果',price:100},
        {name:'香蕉',price:101},
    ])
    // 定义acticons
    const goodsAdd = (goodsObj)=>{
        goodsList.value.push(goodsObj)
    }
    // 定义getters
    const filtersGoodsList = computed(()=>{
        return goodsList.value.filter(item=>item.price<=100) 
    })
    return {
        goodsList,
        goodsAdd,
        filtersGoodsList
    }
},{persist:true})